package com.beaven.imserver.net.bean.db;

import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

/**
 * author: Beaven
 * time: 2017/5/17 11:33
 * <p>
 * 用户的关系表，好友关系的实现
 */
@Entity
@Table(name = "TB_USER_FOLLOW")
public class UserFollow {

  // 主键
  @Id
  @PrimaryKeyJoinColumn
  @GeneratedValue(generator = "uuid")
  @GenericGenerator(name = "uuid", strategy = "uuid2")
  @Column(updatable = false, nullable = false)
  private String id;

  /**
   * 添加好友的发起人,就是我
   * 添加一个好友，就是一条记录
   * 一个User对应多个UserFollow
   * 每条记录必须是有发起人，不可选
   */
  @ManyToOne(optional = false)
  // 定义关联的表字段名为originId,对应User.Id
  @JoinColumn(name = "originId")
  private User origin;
  @Column(nullable = false, updatable = false, insertable = false)
  private String originId;

  /**
   * 添加的目标好友，我的好友
   * 多个UserFollow对于一个User
   */
  @ManyToOne(optional = false)
  @JoinColumn(name = "targetId")
  private User target;
  @Column(nullable = false, updatable = false, insertable = false)
  private String targetId;

  /**
   * 目标好友所在的分组
   */
  @ManyToOne(optional = false)
  @JoinColumn(name = "categoryId")
  private Category category;
  @Column(nullable = false, updatable = false, insertable = false)
  private String categoryId;

  // 别名，对好友的备注
  @Column
  private String alias;

  // 创建时间戳
  @CreationTimestamp
  @Column(nullable = false)
  private LocalDateTime createAt = LocalDateTime.now();

  //更新时间戳
  @UpdateTimestamp
  @Column(nullable = false)
  private LocalDateTime updateAt = LocalDateTime.now();

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public User getOrigin() {
    return origin;
  }

  public void setOrigin(User origin) {
    this.origin = origin;
  }

  public String getOriginId() {
    return originId;
  }

  public void setOriginId(String originId) {
    this.originId = originId;
  }

  public User getTarget() {
    return target;
  }

  public void setTarget(User target) {
    this.target = target;
  }

  public String getTargetId() {
    return targetId;
  }

  public void setTargetId(String targetId) {
    this.targetId = targetId;
  }

  public String getAlias() {
    return alias;
  }

  public void setAlias(String alias) {
    this.alias = alias;
  }

  public LocalDateTime getCreateAt() {
    return createAt;
  }

  public void setCreateAt(LocalDateTime createAt) {
    this.createAt = createAt;
  }

  public LocalDateTime getUpdateAt() {
    return updateAt;
  }

  public void setUpdateAt(LocalDateTime updateAt) {
    this.updateAt = updateAt;
  }

  public Category getCategory() {
    return category;
  }

  public void setCategory(Category category) {
    this.category = category;
  }

  public String getCategoryId() {
    return categoryId;
  }

  public void setCategoryId(String categoryId) {
    this.categoryId = categoryId;
  }
}
